package easy;

public class Solution_1576 {

    private char[] array = new char[]{'a', 'b'};

    public String modifyString(String s) {
        if (s.length() == 1 && s.equals("?")) {
            return "a";
        }
        char[] chars = s.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            if (chars[i] == '?') {
                char c = getChar(chars, i);
                chars[i] = c;
            }
        }
        return new String(chars);
    }

    private char getChar(char[] chars, int i) {
        char left, right;
        if (i == 0) {
            right = chars[i + 1];
            left = right;
        } else if (i == chars.length - 1) {
            left = chars[i - 1];
            right = left;
        } else {
            left = chars[i - 1];
            right = chars[i + 1];
        }
        if (left == '?') {
            left = 'a';
        }
        if (right == '?') {
            right = 'a';
        }
        int max;
        if (Math.abs(right - left) > 1) {
            max = Math.min(left, right) + 1;
        } else {
            int min = Math.min(left, right);
            if (min <= 98) {
                max = 122;
            } else {
                max = 97;
            }
        }
        return (char) (max);
    }

    public static void main(String[] args) {
        Solution_1576 model = new Solution_1576();
        System.out.println(model.modifyString("?zs"));
        System.out.println(model.modifyString("ubv?w"));
        System.out.println(model.modifyString("j?qg??b"));
        System.out.println(model.modifyString("??yw?ipkj?"));
        System.out.println(model.modifyString("a?z"));
        System.out.println(model.modifyString("?zs"));
    }
}
